<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>

<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
	<title>停车场--${headerTitle }</title>
	<base href="<%=basePath%>">
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1";/><!-- IE的渲染模式 -->
    <meta name="keywords" content="信帧,teleframe,iparking,I停车,爱停车,blackshadowwalker" />
	<meta name="description" content="信帧,teleframe,iparking,I停车,爱停车,blackshadowwalker" />
	<meta name="author" content="blackshadowwalker" />
    
	<link href="css/common.css" rel="stylesheet"/>
	<link href="bootstrap/3/css/bootstrap.css" rel="stylesheet"/>

	<script src="scripts/jquery/jquery-1.7.min.js"></script>
	<script src="bootstrap/3/js/bootstrap.min.js"></script>
	<link href="bootstrap/3/css/bootstrap-timepicker.min.css" rel="stylesheet"/>
	<script src="bootstrap/3/js/bootstrap-timepicker.js"></script>
	
	<script src="scripts/validateForm.js?t=123"></script>
	<script src="index/js/index.js" type="text/javascript"></script>
	
	<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=15EdmORyQbzDsGOQHiTsW2oh"></script>
	
	<script type="text/javascript">
		var msg = "${msg}";
		if(msg!="")
			alert(msg);
			
	</script>
	
	<style>
		body{
			margin-left: 10px;
			margin-top: 7px;
			width:98%;
		}
	</style>

</head>

<body>

<div  style="width:100%;">
	
	<div id="div-form">

		<div>
			<div class="alert-info" >
				<a href="${action }" class="btn btn-warning">返回</a>
				<div style="display:inline;margin-left:30px;color:#f00;">
					${msg }
				</div>
			</div >
		</div>
		
		<form id="myform" name="myform" class="form-horizontal" role="form"  action="${action }?id=${id}&method=${method}" method="post" >
				
			  <div class="hidden">
				token : <s:token/>
				车场信息来源（1：自己注册；2：外部引入3：合同用户）:<input name="parkInfo.source" value="${parkInfo.source }"/>	
			  </div>
			  
			  <div class="form-group">
			    <label class="col-sm-2 control-label"><span style="color:#f00">*</span> 停车场名称：</label>
			    <div class="col-sm-5">
			    		<input type="text" class="form-control" name="parkInfo.PName"  value="${parkInfo.PName }" maxlength="60"  placeholder="停车场名称"
			    			isValidate="true" notEmpty="true"  notSpecial="true"  specialChar="~!@#$%^&*?" leng="60" minLeng="0"/>
				      	 <span class="errorMessage" >
							<s:property value="errors['parkInfo.PName'][0]" />
						</span>
			      	(支持字母、数字、下划线，长度6-20)
			    </div>
			  </div>
			  <div class="form-group">
			    <label class="col-sm-2 control-label"><span style="color:#f00">*</span> 营业编号：</label>
			    <div class="col-sm-5">
			    		<input type="text" class="form-control" name="parkInfo.businessNo"  value="${parkInfo.businessNo }" maxlength="60" placeholder="车场营业编号"
			    			isValidate="true"  notSpecial="true"  specialChar="~!@#$%^&*?" leng="60" minLeng="0"/>
				      	 <span class="errorMessage" >
							<s:property value="errors['parkInfo.businessNo'][0]" />
						</span>
			    </div>
			  </div>
		     <div class="form-group">
			    <label class="col-sm-2 control-label"><span style="color:#f00">*</span>停车场描述：</label>
			    <div class="col-sm-5">
			      	<textarea type="text" class="form-control" name="parkInfo.PDesc"  value="${parkInfo.PDesc }" placeholder="停车场描述" 
			      	isValidate="true" notEmpty="false"  notSpecial="true"  specialChar="~!@#$%^&*|?" leng="200" minLeng="0"  ></textarea>
			      	 <span class="errorMessage" >
						<s:property value="errors['parkInfo.PDesc'][0]" /> 
					</span>
			    </div>
			  </div>
			  
		     <div class="form-group">
			    <label class="col-sm-2 control-label"><span style="color:#f00">*</span>停车场类型：</label>
			    <div class="col-sm-5">
			    	<select  class=form-control  name="parkInfo.PType" >
						<option value="1" selected>地上停车场</option>
						<option value="2" >地下停车场</option>
						<option value="3" >楼宇停车场</option>
					</select>
					<script>
			    		 $("select[name='parkInfo.PType']").val("${parkInfo.PType}");
			    	</script>
			    </div>
			  </div>
			  <div class="form-group">
			    <label class="col-sm-2 control-label"> 白天单价：</label>
			    <div class="col-sm-5">
			    	<div class="input-group">
				      <input class="form-control" type="text" name="parkInfo.dayPrice" value="${parkInfo.dayPrice }" placeholder="单价" isValidate="true" notEmpty="false"  isFloat="true" >
				      <div class="input-group-addon">元，每</div>
				      <input class="form-control" type="text" name="parkInfo.dayTimeUtil" value="${parkInfo.dayTimeUtil }"  placeholder="记时单位" isValidate="true" notEmpty="false"  isFloat="true" >
				      <div class="input-group-addon">小时</div>
				    </div>
			    </div>
			  </div>
			  <div class="form-group">
			    <label class="col-sm-2 control-label"> 白天工作时间：</label>
			    <div class="col-sm-5">
			    	<div class="input-group" >
				      <div class="input-group-addon" ><i class="glyphicon ">上班:</i></div>
				      <input class="form-control timepicker start-time glyphicon-calendar" name="parkInfo.dayStartTime" value="${parkInfo.dayStartTime }" default="8:00"  type="text" placeholder="上班" 
				      		  readonly>
				      <div class="input-group-addon"><i class="glyphicon">下班:</i></div>
				      <input class="form-control timepicker end-time"  name="parkInfo.dayEndTime" value="${parkInfo.dayEndTime }" default="20:00"  type="text" placeholder="下班" 
				      		 readonly>
				    </div>
			    </div>
			  </div>
			  	  <div class="form-group">
			    <label class="col-sm-2 control-label"> 夜间单价：</label>
			    <div class="col-sm-5">
			    	<div class="input-group">
				      <input class="form-control" type="text" name="parkInfo.nightPrice" value="${parkInfo.nightPrice }" placeholder="单价" isValidate="true" notEmpty="false"  isFloat="true" >
				      <div class="input-group-addon">元，每</div>
				      <input class="form-control" type="text" name="parkInfo.nightTimeUtil" value="${parkInfo.nightTimeUtil }" placeholder="记时单位" isValidate="true" notEmpty="false"  isFloat="true" >
				      <div class="input-group-addon">小时</div>
				    </div>
			    </div>
			  </div>
			  <div class="form-group">
			    <label class="col-sm-2 control-label"> 夜间工作时间：</label>
			    <div class="col-sm-5">
			    	<div class="input-group" >
			    	  <div class="input-group-addon" ><i class="glyphicon ">上班:</i></div>
				      <input class="form-control timepicker start-time" name="parkInfo.nightStartTime" value="${parkInfo.nightStartTime }" default="20:00"  type="text" placeholder="上班" 
				      		  readonly>
				      <div class="input-group-addon"><i class="glyphicon">下班</i></div>
				      <input class="form-control timepicker end-time"  name="parkInfo.nightEndTime" value=${parkInfo.nightEndTime } default="8:00"  type="text" placeholder="下班" 
				      		 readonly>
				    </div>
			    </div>
			  </div>
			  <div class="form-group">
			    <label class="col-sm-2 control-label"><span style="color:#f00">*</span>位置：</label>
			    <div class="col-sm-5">
					<input type="hidden" name="parkInfo.longitude" value="${parkInfo.longitude}"  placeholder="经度" isValidate="true"  notEmpty="false" readonly/> 	
					<input type="hidden" name="parkInfo.latitude" value="${parkInfo.latitude}"  placeholder="纬度" isValidate="true"  notEmpty="false" readonly/>
					<div class="input-group" >
						<input class="form-control" type="text" name="parkInfo.addr" value="${parkInfo.addr }" readonly 
							isValidate="true" notEmpty="true"  notSpecial="true"  specialChar="~!@#$%^&*?" />
						<div class="input-group-addon btn" id="setpostion">
							<i class="glyphicon glyphicon-map-marker"> 自定义位置</i>
						</div>
					</div>
			    </div>
			  </div>
			  <div class="form-group">
			    <label class="col-sm-2 control-label"><span style="color:#f00">*</span>车场电话：</label>
			    <div class="col-sm-5">
					<input type="text" class="form-control" name="parkInfo.telePhone" value="${parkInfo.telePhone}"  placeholder="车场电话" 
						isValidate="true" notEmpty="true"  notSpecial="true"  specialChar="~!@#$%^&*?"   /> 	
			    </div>
			  </div>
			  <div class="form-group">
			    <label class="col-sm-2 control-label"><span style="color:#f00">*</span>总车位数：</label>
			    <div class="col-sm-5">
					<input type="text" class="form-control" name="parkInfo.parkNumber" value="${parkInfo.parkNumber }"  placeholder="总车位数" 
						isValidate="true" notEmpty="true"  notSpecial="true"  specialChar="~!@#$%^&*?" isInteger="true" /> 	
			    </div>
			  </div>
			  <div class="form-group">
			    <label class="col-sm-2 control-label"><span style="color:#f00">*</span>剩余车位数：</label>
			    <div class="col-sm-5">
					<input type="text" class="form-control" name="parkInfo.remainderParkNumber" value="${parkInfo.remainderParkNumber }"  placeholder="剩余车位数" 
						isValidate="true" notEmpty="true"  notSpecial="true"  specialChar="~!@#$%^&*?" isInteger="true"/> 	
			    </div>
			  </div>
			  <div class="form-group">
			    <label   class="col-sm-2 control-label"><span style="color:#f00">*</span>是否支持预定：</label>
			    <div class="col-sm-5" >
			    	<select  class=form-control  name="parkInfo.orderable" >
						<option value="1" selected>支持预订</option>
						<option value="0" >不支持预定</option>
					</select>
					<script>
			    		 $("select[name='parkInfo.orderable']").val("${parkInfo.orderable}");
			    	</script>
			    </div>
			  </div>
		  	  <div class="form-group">
			    <label class="col-sm-2 control-label"><span style="color:#f00">*</span>收费员修改收费金额：</label>
			    <div class="col-sm-5">
					<select  class=form-control  name="parkInfo.switchEditAmount" >
						<option value="0" selected>不可修改</option>
						<option value="1" >可修改</option>
					</select>
					<script>
			    		 $("select[name='parkInfo.switchEditAmount']").val("${parkInfo.switchEditAmount}");
			    	</script>
			    </div>
			  </div>
			
		  	 
		  	  <div class="form-group">
			    <label class="col-sm-2 control-label"><span style="color:#f00">*</span>是否收费：</label>
			    <div class="col-sm-5">
					<select  class=form-control  name="parkInfo.isFree" >
						<option value="0" selected>收费车场</option>
						<option value="1" >免费</option>
					</select>
					<script>
			    		 $("select[name='parkInfo.isFree']").val("${parkInfo.isFree}");
			    	</script>
			    </div>
			  </div>
			   <div class="form-group">
			    <label class="col-sm-2 control-label"><span style="color:#f00">*</span>预约小费开关：</label>
			    <div class="col-sm-5">
					<select  class=form-control  name="parkInfo.switchGratuity" onchange="IsFreeChanged();">
						<option value="0" selected>不可收小费</option>
						<option value="1" >可收小费</option>
					</select>
					<script>
			    		 $("select[name='parkInfo.switchGratuity']").val("${parkInfo.switchGratuity}");
			    		 IsFreeChanged();
			    		 function IsFreeChanged(){
			    		 	if($("select[name='parkInfo.switchGratuity']").val()=="1"){
			    		 		$("div.form-group[name='parkInfo.minGratuity']").show(500);
			    		 	}else{
			    		 		$("div.form-group[name='parkInfo.minGratuity']").hide(500);
			    		 	}
			    		 }
			    	</script>
			    </div>
			  </div>
		      <div class="form-group" name="parkInfo.minGratuity" style="display:none;" >
			    <label class="col-sm-2 control-label"><span style="color:#f00">*</span>最低小费收取额度：</label>
			    <div class="col-sm-5">
			    	<div class="input-group" >
						<input class="form-control" type="text" name="parkInfo.minGratuity" value="${parkInfo.minGratuity }"  
							isValidate="true" isInteger="true"/>
						<div class="input-group-addon btn" id="setpostion">
							<i class="glyphicon "> 元</i>
						</div>
					</div>
			    </div>
			  </div>
			  
		  	  <div class="form-group">
			    <label class="col-sm-2 control-label"><span style="color:#f00">*</span>车场归属：</label>
			    <div class="col-sm-5">
					<select  class=form-control  name="parkInfo.attribution" onchange="AttributionChanged(this);" >
						<option value="2" selected >企业</option>
						<option value="1" >个人</option>
						<option value="3" >政府</option>
						<option value="0" >暂无</option>
					</select>
					<script>
			    		 $("select[name='parkInfo.attribution']").val("${parkInfo.attribution}");
			    		 function AttributionChanged(obj){
			    		 	if($(obj).val()=="2"){
			    		 		$("div.form-group[name='parkInfo.enterpriseName']").show(500);
			    		 	}else{
			    		 		$("div.form-group[name='parkInfo.enterpriseName']").hide(500);
			    		 	}
			    		 		
			    		 }
			    	</script>
			    </div>
			  </div>
			  
			  <div class="form-group" name="parkInfo.enterpriseName">
			    <label class="col-sm-2 control-label"><span style="color:#f00">*</span>企业名称：</label>
			    <div class="col-sm-5">
					<input class="form-control" type="text" name="parkInfo.enterpriseName" value="${parkInfo.enterpriseName}"   placeholder="企业名称"
						isValidate="true"  />
			    </div>
			  </div>
			  <div class="form-group">
			    <label   class="col-sm-2 control-label"><span style="color:#f00">*</span>车场状态：</label>
			    <div class="col-sm-5">
					<select  class=form-control  name="parkInfo.status" >
						<option value="-2" selected>暂停营业中</option>
						<!-- <option value="-1">已删除</option> -->
						<!-- <option value="0">已冻结</option> -->
						<!-- <option value="1">未审核</option> -->
						<!-- <option value="2">审核中</option> -->
						<option value="3">正常</option>
					</select>
					<script>
			    		 $("select[name='parkInfo.status']").val("${parkInfo.status}");
			    	</script>
			    </div>
			  </div>
			  <div class="form-group">
			    <label for="inputEmail3" class="col-sm-2 control-label"> </label>
			    <div class="col-sm-5">
		    			<input class="btn btn-success btn-lg btn-block"  type=submit value="${headerTitle }"   />
						<input class="btn btn-primary btn-lg btn-block"  type="reset" value="重置"  />
			     </div>
			  </div>
			  <br />
			  <br />
			  <br />
		</form>
	
	</div> <!-- div of form -->
	
	
	<div id="div-map" style="display:none;">
		<div id="baidumap" style="width:99%;height:500px;">
			 正在加载.....
		</div>
		<i  id="gobackform" class="glyphicon glyphicon-arrow-left" style="z-index:999999;position:absolute;cursor:pointer;left:0px;top:-2px;font-size: 24px;"
			title="返回"
		 ></i>
	</div>


</div>
		
		<script>
			
			/** 获取浏览器高度和宽度 **/
			var myWidth = 0, myHeight = 0;
			
			function resizewndow() 
			{ 
			    if( typeof( window.innerWidth ) == 'number' ) {
			        //Non-IE
			        myWidth = window.innerWidth;
			        myHeight = window.innerHeight;
			    } 
			    else if(document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight)){
			        //IE 6+ in 'standards compliant mode'
			        myWidth = document.documentElement.clientWidth;
			        myHeight = document.documentElement.clientHeight;  
			    }
			    if(window.console)
			    	console.log("myWidth:"+myWidth+", myHeight:"+myHeight);
			} 
			window.onresize = resizewndow;
		
			function GPS(x,y){
				this.x = x;
				this.y = y;
			}
			
			function BMap2GPSCallBack(gps){
				if(window.console){
					console.log(gps);
				}
				$("input[name='parkInfo.longitude']").val( gps.x );
			  	$("input[name='parkInfo.latitude']").val( gps.y );
			}
			
			function BMap2GPS(x,y, callbackGPS){
				var gps = new GPS(x, y);
				var url = "TMapAction?method=BMap2GPS";
				$.ajax({
					url: url,
					type: 'post',
					data: {
							longitude: x, 
							latitude: y
						},
					dataType: 'json',
					success: function(retdata){
							if(window.console){
								console.log(retdata);
							}
							if(retdata.error==0){
								gps = new GPS(retdata.data.x, retdata.data.y);
							}
							callbackGPS(gps);
						},
					error : function(httpxml, status, error){
							alert(error);
						}
				});
			}
		
				
			$(document).ready(function(){
				
				$("textarea[name='parkInfo.PDesc']").val("${parkInfo.PDesc}");
				
				$("#setpostion").click(function(){
					$("#div-form").animate({
						height: 'toggle', 
						opacity: 'toggle' 
					},1000);
					$(window.top).scrollTop(50);
					window.top.setIframeWH(-1, $("#baidumap"));
					$("#div-map").show(1000, function(){
					 
					});
					
				});
				
				$("#gobackform").click(function(){
					$("#div-form").show(1000);
					$("#div-map").slideDown(1000, function(){ 
						$("#div-map").hide();
					});
				});
				
				$("#myform input[type='submit']").click(function(e){
				    e.preventDefault();//阻止提交按钮的默认 action
				//	  alert("Submit prevented");
					if(!$("#myform").validateForm()){
						return ;
					}
					var btn = $(this);
			  		btn.val("正在提交...");
			  		btn.addClass("disabled");
			  		$(btn).parent().children("input[type='reset']").addClass("disabled");
					$("#myform").submit();
				});
				
				//设定时间选择器  url : http://jdewit.github.io/bootstrap-timepicker/index.html  DateTime : http://www.eyecon.ro/bootstrap-datepicker/
				$("input.timepicker").each(function(){
	    			var obj =  $(this);
	    			var defaultval = obj.attr("default");
	    			var val = obj.val();
	    			if(val=="")
	    				val = defaultval;
	    			obj.timepicker({
		                template: 'dropdown', //false | 'dropdown' | 'modal'
		                showInputs: true,
		                minuteStep: 5,
		                showMeridian: false,
		                disableFocus: false,
		                defaultTime: val
		            });
		            obj.click(function() {//点击此timepicker时，先关闭所有的timepicker，在开启此timepicker
		            	$("input.timepicker").each(function(){
		            		$(this).timepicker('hideWidget');
		            	});
		            	$(this).timepicker('showWidget');
					});
	    		});
	    		
	    		var longitude = "${parkInfo.longitude}";
	    		var latitude = "${parkInfo.latitude}";
	    		var map = null;
	    		var gc = new BMap.Geocoder();    
	    		
	    		//百度地图
	    		setTimeout(function(){
					// 百度地图API功能
					map = new BMap.Map("baidumap");            // 创建Map实例
					var point = new BMap.Point( longitude,  latitude);    // 创建点坐标
					var zoom = 12;
					if(longitude!="")
						zoom = 18;
					map.centerAndZoom(point, zoom);                     // 初始化地图,设置中心点坐标和地图级别。
					map.setCurrentCity("北京");          // 设置地图显示的城市 此项是必须设置的
					
					map.enableScrollWheelZoom();                            //启用滚轮放大缩小
					map.enableDragging(); //开启拖拽
					map.enableInertialDragging();//启用地图惯性拖拽，默认禁用。
					
					map.addControl(new BMap.MapTypeControl({mapTypes: [BMAP_NORMAL_MAP,BMAP_HYBRID_MAP]}));     //2D图，卫星图
					map.addControl(new BMap.MapTypeControl({anchor: BMAP_ANCHOR_TOP_RIGHT}));    //左上角，默认地图控件
					
					map.addControl(new BMap.NavigationControl());  //添加默认缩放平移控件
					
					//IP定位获取当前城市
					if(longitude==""){
						function myFun(result){
						    var cityName = result.name;
						    map.setCenter(cityName);
						}
						var myCity = new BMap.LocalCity();
						myCity.get(myFun);//设置IP定位获取当前城市
					}else{
						setMarker( longitude,  latitude); 
					}
					
					//鼠标点击拾取坐标
					map.addEventListener("click", function(e){
						
						//BMap.Convertor.translate(gpsPoint,0,translateCallback);     //真实经纬度转成百度坐标
				//		BMap2GPS(e.point.lng,  e.point.lat, BMap2GPSCallBack);// 百度经纬度转 GPS 
				
						$("input[name='parkInfo.longitude']").val( e.point.lng );
					  	$("input[name='parkInfo.latitude']").val(  e.point.lat );
					  	
					  	setMarker( e.point.lng, e.point.lat );
					  
					});
				},3000);
				
				function setMarker(x, y){
					//添加动画标注点
				  	map.clearOverlays();//清除地图上所有覆盖物。
				  	var point = new BMap.Point( x, y);
					var marker = new BMap.Marker(point);  // 创建标注
					map.addOverlay(marker);              // 将标注添加到地图中
					marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画
					
					//反地址解析
					gc.getLocation(point, function(rs){
				        var addComp = rs.addressComponents;
				        $("input[name='parkInfo.addr']").val(addComp.province + " " + addComp.city + " " + addComp.district + " " + addComp.street + "" + addComp.streetNumber);
				    });  
				}
				
			});
			
			
			
			
								
		</script>
		
	</body>
</html>